import 'package:get/get.dart';
import 'package:sp_util/sp_util.dart';
import 'package:yp/services/api.dart';

import 'state.dart';

class ViewCommentsLogic extends GetxController {
  final state = ViewCommentsState();

  @override
  void onInit() {
    super.onInit();
    state.orderInformationMap = Get.arguments;
    print("orderInformationMap====${state.orderInformationMap}");
    requestData();
  }

  void requestData() {
    var params = {
      'use_platform': 2,
      'ec_shop_num_id': state.orderInformationMap['ec_shop_num_id'],
      'work_flag': 1,
      'tml_num_id': state.orderInformationMap['order_num_id'] == null
          ? state.orderInformationMap['tml_num_id']
          : state.orderInformationMap['order_num_id'], // 订单号
      'page_size': '100000',
      'page_num': '1',
      'access_token': SpUtil.getString('token'),
    };
    Api.queryEvaluateInformation(params).listen((event) {
      print('评论查询成功！   event = $event');
      if (event['code'] == 0) {
        if (event['item_infos'] != null) {
          state.commentsList = event['item_infos'];
        } else {
          state.commentsList = [];
        }
      } else {
        state.commentsList = [];
      }
      update();
    }, onError: (error) {
      print('评论查询失败！   error = $error');
      state.commentsList = [];
    });
  }
}
